import os

ACCESS_READ = 1
ACCESS_WRITE = 2
ACCESS_SEEK = 4
ACCESS_RW = ACCESS_READ | ACCESS_WRITE
ACCESS_RWS = ACCESS_RW | ACCESS_SEEK

NOT_KNOWN = -1

INTEGRITY_OK = 0
INTEGRITY_BROKEN = 1
INTEGRITY_NOT_EXIST = 2



class FileOperations:

    
    def seek(self, offset, whence = os.SEEK_SET):
        pass
    
    def read(self, size = -1):
        return None
    
    def write(self, buf, size = -1):
        pass
     
    def open(self, mode):
        pass
    

    def tell(self):
        return 0
    
    def close(self):
        pass
    
    def size(self):
        return NOT_KNOWN
    
    def description(self):
        return ""
    
    def path(self):
        return None



class FileSystemOperations:
    def create(self, path):
        """
        Return a file at path, not open.
        """
        return None
    
    def open(self, path):
        return None
    
    def delete(self, path):
        pass
    
    def exists(self, path):
        return False
    
    def find(self, namepatten, inpath = None):
        return []   # return matched filename in full path, find in inpath, if inpath is None, find in current path
    
    """
    The following is for fs impl.
    """
    def getBlockSize(self):
        return 4096
    
    def isDirectory(self, path): # for directory structure file system
        return False
    
    def isFile(self, path):
        return False
    
    def mkdir(self, path, permission):
        pass
    
    def rename(self, srcpath, dstpath):
        pass
    
    def listpath(self, pathpattern):
        pass
    
    
def integrity_and(intg1, intg2):
    return integ_and_dict[(intg1, intg2)]

integ_and_dict = {(INTEGRITY_OK, INTEGRITY_OK):INTEGRITY_OK,
                  (INTEGRITY_OK, INTEGRITY_BROKEN):INTEGRITY_BROKEN,
                  (INTEGRITY_OK, INTEGRITY_NOT_EXIST):INTEGRITY_BROKEN,
                  (INTEGRITY_BROKEN, INTEGRITY_OK):INTEGRITY_BROKEN,
                  (INTEGRITY_BROKEN, INTEGRITY_BROKEN):INTEGRITY_BROKEN,
                  (INTEGRITY_BROKEN, INTEGRITY_NOT_EXIST):INTEGRITY_BROKEN,
                  (INTEGRITY_NOT_EXIST, INTEGRITY_OK):INTEGRITY_BROKEN,
                  (INTEGRITY_NOT_EXIST, INTEGRITY_BROKEN):INTEGRITY_BROKEN,
                  (INTEGRITY_NOT_EXIST, INTEGRITY_NOT_EXIST):INTEGRITY_NOT_EXIST}

def integrity_or(intg1, intg2):
    return integ_or_dict[(intg1, intg2)]

integ_or_dict = {(INTEGRITY_OK, INTEGRITY_OK):INTEGRITY_OK,
                (INTEGRITY_OK, INTEGRITY_BROKEN):INTEGRITY_OK,
                (INTEGRITY_OK, INTEGRITY_NOT_EXIST):INTEGRITY_OK,
                (INTEGRITY_BROKEN, INTEGRITY_OK):INTEGRITY_OK,
                (INTEGRITY_BROKEN, INTEGRITY_BROKEN):INTEGRITY_BROKEN,
                (INTEGRITY_BROKEN, INTEGRITY_NOT_EXIST):INTEGRITY_BROKEN,
                (INTEGRITY_NOT_EXIST, INTEGRITY_OK):INTEGRITY_OK,
                (INTEGRITY_NOT_EXIST, INTEGRITY_BROKEN):INTEGRITY_BROKEN,
                (INTEGRITY_NOT_EXIST, INTEGRITY_NOT_EXIST):INTEGRITY_NOT_EXIST}
